home *** CD-ROM | disk | FTP | other *** search
/ The 640 MEG Shareware Studio 2 / The 640 Meg Shareware Studio CD-ROM Volume II (Data Express)(1993).ISO / clang / cuj1008.zip / 1008098A < prev    next >
Text File  |  1992-02-17  |  6KB  |  179 lines

  1. /*-------------------- ShowTch.c -------------------*
  2.  *                                                  *
  3.  * Module:    ShowTch.c                             *
  4.  * Purpose:   To provide a demonstration about how  *
  5.  *            to use function GetTouch().           *
  6.  * Author:    W. Harvey Gray                        *
  7.  * Compiler:  Microsoft 5.0                         *
  8.  *                                                  *
  9.  * Functions: (extern)                              *
  10.  *            main                                  *
  11.  *                                                  *
  12.  * Variables: There are no external variables used  *
  13.  *            or defined by this module.            *
  14.  *                                                  *
  15.  * Copyright 1992, W. Harvey Gray.  May be used     *
  16.  *   freely, if authorship and publication are      *
  17.  *   acknowledged.                                  *
  18.  *                                                  *
  19.  *--------------------------------------------------*/
  20.  
  21. #include <bios.h>
  22. #include <conio.h>
  23. #include <stdlib.h>
  24. #include <string.h>
  25. #include <stdio.h>
  26.  
  27. #include "dvrfunc.h"
  28. #include "GetTouch.h"
  29.  
  30. /*--------------------------------------------------*
  31.  *                static prototypes                 *
  32.  *--------------------------------------------------*/
  33.  
  34. static void print_touch( void );
  35. static void touch_loop( void );
  36.  
  37. /*--------------------------------------------------*
  38.  *     extern function   main()                     *
  39.  *--------------------------------------------------*/
  40.  
  41. int main( int argc, char **argv ) {
  42.  
  43. /*--------------------------------------------------*
  44.  * Purpose:                                         *
  45.  *                                                  *
  46.  *   Demonstrates a simple routine that reads a     *
  47.  * complete touchscreen touch and prints its        *
  48.  * statistics.                                      *
  49.  *                                                  *
  50.  *--------------------------------------------------*/
  51.  
  52.     struct infodata *pinfo;
  53.  
  54.     puts( "ShowTch V1.0" );
  55.     puts( " A test program for function GetTouch." );
  56.  
  57.     if ( ! finddriver() ) {   /* Check for ELODEV. */
  58.  
  59.         puts( "\nELODEV not installed." );
  60.         exit( 1 );
  61.     }
  62.     /*----------------------------------------------*
  63.      * Check for correct device driver version.     *
  64.      *----------------------------------------------*/
  65.  
  66.     pinfo = malloc( sizeof( struct infodata ) );
  67.     driverinfo( pinfo );
  68.  
  69.     if ( ( pinfo->driverversionmajor * 10 +
  70.            pinfo->driverversionminor ) < 14 ) {
  71.  
  72.         puts( "\nELODEV not >= version 1.4" );
  73.         exit( 2 );
  74.     }
  75.     free( pinfo );
  76.  
  77.     /*----------------------------------------------*
  78.      * Startup the touchscreen device driver.       *
  79.      *----------------------------------------------*/
  80.  
  81.     setmode( BUFFERED | UNTOUCH | STREAM );
  82.     opentouch();
  83.     enabletouch();
  84.     initdelay();
  85.  
  86.     /*----------------------------------------------*
  87.      *   Set the button radius to be 4% of the      *
  88.      * diagonal dimension of the touchscreen.       *
  89.      *----------------------------------------------*/
  90.  
  91.     InitializeTouch();
  92.     SetButtonRadius( 4096/25 );
  93.  
  94.     /*----------------------------------------------*
  95.      *   Continue reading touches until the key-    *
  96.      * board is hit.                                *
  97.      *----------------------------------------------*/
  98.  
  99.     while ( ! _bios_keybrd( _KEYBRD_READY ) )
  100.         touch_loop();
  101.                          /* Flush keyboard buffer. */
  102.  
  103.     while ( _bios_keybrd( _KEYBRD_READY ) )
  104.         getch();
  105.  
  106.     closetouch();
  107.     exit( 0 );
  108. }
  109.  
  110. /*--------------------------------------------------*
  111.  *     static function   print_touch()              *
  112.  *--------------------------------------------------*/
  113.  
  114. static void print_touch( void ) {
  115.  
  116. /*--------------------------------------------------*
  117.  * Purpose:                                         *
  118.  *                                                  *
  119.  *   Print the touch statistics.                    *
  120.  *                                                  *
  121.  *--------------------------------------------------*/
  122.  
  123.     struct touchit *pti;
  124.  
  125.     pti = TouchInfo();
  126.     printf( "\nTouch pts = %d;", pti->n );
  127.     printf( "\n (X,Y)cen = (" );
  128.     printf( "%5d,",  pti->xcen );
  129.     printf( "%5d);", pti->ycen );
  130.     printf( "\n Push button = %s.",
  131.         ( (pti->button) ? "True" : "False" ) );
  132.  
  133.     return;
  134. }
  135.  
  136. /*--------------------------------------------------*
  137.  *     static function   touch_loop()               *
  138.  *--------------------------------------------------*/
  139.  
  140. static void touch_loop( void ) {
  141.  
  142. /*--------------------------------------------------*
  143.  * Purpose:                                         *
  144.  *                                                  *
  145.  *   Read an entire touch and print its statistics  *
  146.  * when an untouch point is received.               *
  147.  *                                                  *
  148.  *--------------------------------------------------*/
  149.  
  150.     boolean button;
  151.     boolean touched;
  152.  
  153.     struct touchxy *ptouch;
  154.  
  155.     /*----------------------------------------------*
  156.      *   Service one complete touch.                *
  157.      *----------------------------------------------*/
  158.  
  159.     touched = FALSE;
  160.     do {
  161.  
  162.         if (( ptouch = GetTouch( &button )) !=
  163.                  (struct touchxy *) NULL ) {
  164.  
  165.             touched = TRUE;  /* Touch point recv'd */
  166.  
  167.             if ( ptouch->ut ) {   /* Is a untouch? */
  168.  
  169.                 print_touch();
  170.                 printf(" (Press any key to stop.)" );
  171.                 break;     /* Finished with touch. */
  172.             }
  173.         }
  174.     }
  175.     while ( touched );
  176.  
  177.     return;
  178. }                                  /* End of file. */
  179.